package org.training.apr;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.training.apr.ConfigurationError;
import org.training.apr.model.Enterprise;

public final class FakeProperties {
	private static final String PAYMENT_SUPERVISION_THRESHOLD = "payment_supervision_threshold";
	
	private static final Properties props = new Properties();

	private static Enterprise hostEnterprise = null;
	
	static {
		InputStream stream = null; 
		try {
			stream = ClassLoader.getSystemClassLoader().getResourceAsStream("conf.properties");
			props.load(stream);
		} catch (IOException e) {
			throw new ConfigurationError("Error reading configuration file", e);
		} finally {
			if(stream != null) {
				try {
					stream.close();
				} catch (IOException e) {
					throw new ConfigurationError("Error closing stream", e);
				}
			}
		}
	}
	
	public static double getSupervisionThreshold() {
		return Double.valueOf(props.getProperty(PAYMENT_SUPERVISION_THRESHOLD, "100000"));
	}
	
	public static Enterprise getHostEnterprise() {
		return hostEnterprise;
	}

	public static void setHostEnterprise(Enterprise e) {
		hostEnterprise = e;
	}
}
